﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using prufa.Interfaces;
using prufa.Models;

namespace prufa.Models
{
    public class GameRepository : IGameRepository
    {
        private DefaultConnection _db = new DefaultConnection();

        public IEnumerable<Game> GetAllGames()
        {
            IEnumerable<Game> games = from n in _db.Games                                     
                                      select n;
            return games;
        }
        public IEnumerable<Game> GetLatestGames()
        {
            IEnumerable<Game> games = (from n in _db.Games
                                      orderby n.GameId descending
                                   select n).Take(10);
            return games;
        }
        public IEnumerable<Game> GetMostPlayed()
        {
            IEnumerable<Game> games = (from n in _db.Games
                                       orderby n.PlayCounter descending
                                       select n).Take(10);
            return games;
        }
        public void AddToPlayCountMylla()
        {
            Game myGame = (from n in _db.Games
                        where n.GameId == 1
                        select n).First();
            myGame.PlayCounter += 1;
            _db.SaveChanges();

        }
        public void AddToPlayCountRisk()
        {
            Game myGame = (from n in _db.Games
                           where n.GameId == 2
                           select n).First();
            myGame.PlayCounter += 1;
            _db.SaveChanges();

        }
    }
}